﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ebusiness_Framework.ConfigLoad
{
    public static class ConfigWebApplicationBuilderExtenions
    {
        /// <summary>
        /// 使用配置加载
        /// </summary>
        /// <param name="webApplicationBuilder"></param>
        /// <returns></returns>
        public static WebApplicationBuilder UseConfigLoad(this WebApplicationBuilder webApplicationBuilder)
        {
            ConfigurationManager configuration = webApplicationBuilder.Configuration;
            var conf = configuration["ASPNETCORE_ENVIRONMENT"];
            if (conf == "Development")
                configuration.AddJsonFile($"appsettings.json", true, true);
            else
                configuration.AddJsonFile($"appsettings.{conf}.json", true, true);

            return webApplicationBuilder;
        }
    }
}
